_content = [ 'password', 'websites', 'config' ];

function tab_password ()
{
	chrome.extension.sendRequest ( { "mode" : "has-master-password" }, function ( response )
	{
		var password = response.data;
		var old_master, new_master;

		if ( password )
			document.getElementById ( "old-pwd" ).style.display = "block";

		tabs_content_show ( "password" );
	} );
}

function tab_websites ()
{
	chrome.extension.sendRequest ( { "mode" : "list-domains" }, function ( response )
	{
		var domains = response.data, doms = [];
		var t, l = domains.length;
		var res = [], d;

		for ( t = 0; t < l; t ++ )
		{
			d = domains [ t ];
			doms.push ( d.replace ( /https*:\/\//, "" ) );
		}

		doms.sort ();

		res.push ( "<table>" );
		for ( t = 0; t < l; t ++ )
		{
			d = doms [ t ];
			res.push ( '<tr><td>' + d + '</td><td>Hello</td></tr>' );
		}
		res.push ( "</table>" );

		document.getElementById ( "websites-table" ).innerHTML = res.join ( "" );

		tabs_content_show ( "websites" );
	} );
}

function tabs_content_show ( name )
{
	var t, l = _content.length;

	for ( t = 0; t < l; t ++ )
	{
		document.getElementById ( 'content-' + _content [ t ] ).style.display = 'none';
	}

	document.getElementById ( 'content-' + name ).style.display = 'block';
}
